package omq.api;

import java.io.IOException;
import java.rmi.RemoteException;

import com.sun.corba.se.pept.transport.Connection;

public class OMQSession 
{
	// connection owner of this session
	private OMQConnection connection;

    // session is transacted or not
    private boolean transacted;

    /**
     * Create a session related to a specific connection. This is used for transaction support (not implemented yet)
     * A session must be used to work against a queue.
     * @param _connection
     * @param _transacted
     */
	public OMQSession(OMQConnection _connection, boolean _transacted) {
		super();
		this.connection = _connection;
		this.transacted = _transacted;
	}
    /**
     * Send a message to a queue.
     * @param queue
     * @param msg
     * @return
     * @throws RemoteException
     */
	public int sendMessage(OMQQueue queue, OMQMessage msg) throws RemoteException
	{
		return connection.sendMessage(queue, msg);
	}
	/**
	 * Receive a message from a queue.
	 * @param queue
	 * @return
	 * @throws RemoteException
	 * @throws IOException
	 */
	public OMQMessage receiveMessage(OMQQueue queue) throws RemoteException, IOException 
	{
		return connection.receiveMessage(queue);
	}
	/**
	 * Peek a message on a queue.
	 * @param queue
	 * @return
	 * @throws RemoteException
	 * @throws IOException
	 */
	public OMQMessage peekMessage(OMQQueue queue) throws RemoteException, IOException 
	{
		return connection.peekMessage(queue);
	}
	/**
	 * Get the messageID of the last sent or received message
	 * @return
	 */
	public String getLastMessageID()
	{
		return connection.getLastMessageID();
	}
	/**
	 * Get the error code of the last action performed
	 * @return
	 */
	public  int getLastErrorCode()
	{
		return connection.getLastErrorCode();
	}
	/**
	 * Get the error code of the last action performed
	 * @return
	 */
	public String getLastErrorDescription()
	{
		return connection.getLastErrorDescription();
	}
	/**
	 * Clean all messages from a queue.
	 * @param queue
	 * @return
	 * @throws RemoteException
	 */
	public int emptyQueue(OMQQueue queue) throws RemoteException
	{
		return connection.emptyQueue(queue);
	}
	/**
	 * Retrieve Queue definitions.
	 * @param queue
	 * @return
	 * @throws RemoteException
	 */
	public OMQQueue getQueueDefinitions(OMQQueue queue)	throws RemoteException
	{
		return connection.getQueueDefinitions(queue);
	}
	
	// TODO
//	public OMQMessage receive(int milliseconds)
//	{
//		
//	}
//	
	
	
//	public OMQMessage receiveMessage(OMQQueue queue)
//	{
//		OMQMessage msg = new OMQMessage();		
//		return msg;
//	}
    
}
